#include "Observer.h"
#include <iostream>
using namespace std;

//using namespace Observer;


class CSubject: public Subject
{
public:
	CSubject():m_s("\0")
	{

	}
	~CSubject()
	{

	}
	void SetState(const string& is)
	{
		m_s = is;
	}
	string GetState()
	{
		return m_s;
	}

private:
	string m_s;
};


class CIObserver:public iObserver
{
public:
	CIObserver(Subject* sub);
	virtual ~CIObserver();
	void Update(Subject* isub);
	void Display();

private:
	Subject*	m_sub;
	string		m_State;

};


CIObserver::CIObserver(Subject* sub)
{
	m_sub = sub;
	m_State = "\0";
	m_sub->addObserver(this);
}

CIObserver::~CIObserver()
{
	m_sub->deleteObserver(this);
	if( m_sub )
		delete m_sub;
}


void CIObserver::Update(Subject* _sub)
{
	m_State = _sub->GetState();
	Display();
}

void CIObserver::Display()
{
	std::cout<<"Current State is "<<m_State<<std::endl;
}



int main()
{
	CSubject* isub = new CSubject();
	CIObserver* io1 = new CIObserver(isub);
	CIObserver* io2 = new CIObserver(isub);

	isub->SetState( "jiaojiangong" );
	isub->Notify();

	isub->SetState( "something new");
	isub->Notify();

	std::cin.get();

	return 0;
}